<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">物流公司</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">物流编码</label>
                    <div class="layui-input-block">
                        <input type="text" name="code" autocomplete="off" placeholder="例:jd" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">公司网址</label>
                    <div class="layui-input-block">
                        <input type="text" name="weburl" autocomplete="off" placeholder="例:https://www.zto.com/" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">图标</label>
                    <div class="layui-input-block">
                      <input type="hidden" name="icon">
                      <button type="button" class="layui-btn" id="icon">上传图片</button>
                      <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1">
                        <p id="demoText"></p>
                      </div>
                    </div>
                </div>   

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script type="text/javascript" charset="utf-8" src="/component/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/component/ueditor/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/component/ueditor/lang/zh-cn/zh-cn.js"></script>

<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
var modules = [
    'upload','form','jquery'
];
layui.use(modules,function(){
    let form = layui.form;
    let $ = layui.jquery;
    let MODULE_PATH = "/{$controller}/";
    var upload = layui.upload;
    //执行实例
    var uploadInst = upload.render({
        elem: '#icon' //绑定元素
        ,url: MODULE_PATH+'upload' //上传接口
        ,done: function(res){
            //上传完毕回调
            if(res.code==1){
                $('[name="icon"]').val(res.savename);
            }
        }
        ,error: function(){
          //请求异常回调
        }
      });
    form.on('submit(user-save)', function(data){

        $.ajax({
            url:MODULE_PATH+'create',
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(result){
                if(result.code==1){
                    layer.msg(result.msg,{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("user-table");
                    });
                }else{
                    layer.msg(result.msg,{icon:2,time:1000});
                }
            }
        })
        
        return false;
    });
})


</script>
<script>
</script>
</body>
</html>